//
//  XMRetweetStatusView.m
//  XMWeibo
//
//  Created by chi on 14-8-26.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMRetweetStatusView.h"
#import "XMStatusFrame.h"
#import "XMStatus.h"
#import "UIImageView+WebCache.h"
#import "XMPhotosView.h"

@interface XMRetweetStatusView ()

#pragma mark - 被转发微博控件

/** 被转发微博昵称 */
@property (nonatomic, weak) UILabel *retweetNameLabel;

/** 被转发微博内容 */
@property (nonatomic, weak) UILabel *retweetContentLabel;

/** 被转发微博配图 */
@property (nonatomic, weak) XMPhotosView *retweetPhotosView;

@end

@implementation XMRetweetStatusView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        //设置属性
        self.image = [UIImage stretchableImageWithName:@"timeline_retweet_background" andLeftCap:0.9 andTopCap:0.5];
        
        // 创建子控件
        [self setupSubviews];
    }
    return self;
}


#pragma mark - 创建子控件
- (void)setupSubviews
{
    //被转发微博昵称
    UILabel *retweetNameLabel = [[UILabel alloc]init];
    retweetNameLabel.backgroundColor = [UIColor clearColor];
    retweetNameLabel.font = kRetweetStatusNameLabelFont;
    retweetNameLabel.textColor = XMColor(55, 92, 148);
    self.retweetNameLabel = retweetNameLabel;
    [self addSubview:retweetNameLabel];
    
    //被转发微博内容
    UILabel *retweetContent = [[UILabel alloc]init];
    retweetContent.numberOfLines = 0;
    retweetContent.font = kRetweetStatusContentLabelFont;
    retweetContent.textColor = XMColor(75, 75, 75);
    self.retweetContentLabel = retweetContent;
    [self addSubview:retweetContent];
    
    //被转发微博配图
    XMPhotosView *retweetPhotosView = [[XMPhotosView alloc]init];
    self.retweetPhotosView = retweetPhotosView;
    [self addSubview:retweetPhotosView];

}

#pragma mark - 设置数据、位置模型
- (void)setStatusF:(XMStatusFrame *)statusF
{
    XMStatus *retweet = statusF.status.retweeted_status;
    
    
    if (retweet) {
         //被转发微博昵称
        self.retweetNameLabel.frame = statusF.retweetNameLabelF;
        self.retweetNameLabel.text = retweet.user.name;
        self.retweetNameLabel.frame = statusF.retweetNameLabelF;
        
        //被转发内容
        self.retweetContentLabel.text = retweet.text;
        self.retweetContentLabel.frame = statusF.retweetContentLabelF;
        
        
        if (retweet.pic_urls.count) {
            self.retweetPhotosView.hidden = NO;
            self.retweetPhotosView.photos = retweet.pic_urls;
            self.retweetPhotosView.frame = statusF.retweetPhotoViewF;
        }
        else {
            self.retweetPhotosView.hidden = YES;
        }
    }
    
  
    
}

@end
